using System;
using System.ComponentModel;

namespace Framework.Library.Core.Utils.Resources
{
    [AttributeUsage(AttributeTargets.All)]
    public abstract class ResourceDescriptionAttribute : DescriptionAttribute
    {
        private bool _localized;
        private IResourceGetter _resourceGetter;

        public ResourceDescriptionAttribute(string description)
            : base(description)
        {
        }

        protected IResourceGetter ResourceGetter
        {
            get
            {
                if (_resourceGetter == null)
                    _resourceGetter = GetResourceGetter();

                return _resourceGetter;
            }
        }

        public override object TypeId
        {
            get { return typeof (DescriptionAttribute); }
        }

        public override string Description
        {
            get
            {
                if (!_localized)
                {
                    _localized = true;
                    DescriptionValue = ResourceGetter.GetString(base.Description);
                }

                return base.Description;
            }
        }

        protected abstract IResourceGetter GetResourceGetter();
    }
}